import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout'
import Home from '@/views/home'
import QA from '@/views/qa'
import Video from '@/views/video'
import My from '@/views/my'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout'
  },

  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      {
        path: 'home', // 默认子路由
        component: Home
      },

      {
        path: 'qa',
        component: QA
      },

      {
        path: 'video',
        component: Video
      },
      {
        path: 'my',
        component: My
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login')

  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    props: true // 将路由参数映射到组件的props中
  },
  {
    path: '/user/profile',
    name: 'user-profile',
    component: () => import('@/views/user-profile')
  }

]

const router = new VueRouter({
  routes
})

export default router
